export ASCEND_DIR=/usr/local/Ascend/ascend-toolkit/latest
export MPI_HOME=/home/sxzhang/opt/hmpi

export OMP_PROC_BIND=true
export OMP_PLACES=threads
export OMP_NUM_THREADS=16

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Ascend/ascend-toolkit/latest/lib64:/home/sxzhang/opt/hmpi/lib/:/usr/local/Ascend/driver/lib64/driver/
#/usr/local/Ascend/ascend-toolkit/latest/aarch64-linux/devlib/linux/aarch64/
set -e


DEVICE_ID=0

if [ $# -eq 0 ]; then
    echo "Please provide a make target as argument"
    exit 1
fi

make $1 && rm -rf test.log

if [ $1 == "perf-mpi-h2d-copy" ]; then
    ${MPI_HOME}/bin/mpirun -n 8 --rankfile rankfile --bind-to core ./bin/perf-mpi-h2d-copy | tee -a test.log
    exit 0
fi

if [ $1 == "perf-mpi-h2d-copy1" ]; then
    ${MPI_HOME}/bin/mpirun -n 2 --rankfile rankfile --bind-to core ./bin/perf-mpi-h2d-copy1 | tee -a test.log
    exit 0
fi

if [ $1 == "perf-mpi-shared-memory" ]; then
    ${MPI_HOME}/bin/mpirun -n 8 --rankfile rankfile --bind-to core ./bin/perf-mpi-shared-memory | tee -a test.log
    exit 0
fi

exit 0
DATA_SIZE=2048
STREAM_NUM_LIST=(1 2 5 10 15 20 25 30)
for STREAM_NUM in ${STREAM_NUM_LIST[@]}
do
    echo "Run on Device:" ${DEVICE_ID} "in" ${DATA_SIZE} "MB by" ${STREAM_NUM} "Streams"
    bin/main ${DEVICE_ID} ${DATA_SIZE} ${STREAM_NUM} >> test.log
done

STREAM_NUM=10
DATA_SIZE_LIST=(125 256 512 1024 2048 3072 4096 5120 6144)
for DATA_SIZE in ${DATA_SIZE_LIST[@]}
do
    echo "Run on Device:" ${DEVICE_ID} "in" ${DATA_SIZE} "MB by" ${STREAM_NUM} "Streams"
    bin/main ${DEVICE_ID} ${DATA_SIZE} ${STREAM_NUM} >> test.log
done

STREAM_NUM=20
DATA_SIZE_LIST=(125 256 512 1024 2048 3072)
for DATA_SIZE in ${DATA_SIZE_LIST[@]}
do
    echo "Run on Device:" ${DEVICE_ID} "in" ${DATA_SIZE} "MB by" ${STREAM_NUM} "Streams"
    bin/main ${DEVICE_ID} ${DATA_SIZE} ${STREAM_NUM} >> test.log
done
